home *** CD-ROM | disk | FTP | other *** search
/ Learn Microsoft Visual Basic 6.0 Now / Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO / media / chap10 / b10d005.cc2 < prev    next >
Text File  |  1998-06-07  |  4KB  |  80 lines

  1. 0, In this demonstration, I'll show you how 
  2. 2, to create a simple text browser that 
  3. 4, can load and display text files on your 
  4. 6, system. The program uses a text box object 
  5. 10, to display the file and a common dialog 
  6. 12, object to open the file. The program is 
  7. 16, running now, so let's see how it works. 
  8. 18, I can click the File menu, and I can 
  9. 21, click the Open command. And when I do, the 
  10. 24, common dialog object uses the ShowOpen 
  11. 26, method to display the Open dialog box. I 
  12. 30, can click a text file in my dialog box, 
  13. 32, and if I click the Open button, Visual 
  14. 35, Basic displays it in a text box window. 
  15. 38, This article is from the American Best 
  16. 40, Pocket Dictionary, published in 1951, and 
  17. 44, describes how to detect counterfeit 
  18. 45, money. And I can see the rest of the 
  19. 47, article by clicking down the scroll bars. And 
  20. 54, I can click back up to the top again if 
  21. 56, I want to. Notice that the program also 
  22. 58, displayed the current filename in a 
  23. 60, label in the top. If I want to go ahead and 
  24. 63, close the file, I can click the File 
  25. 64, menu and click the Close command, and it 
  26. 67, will remove the output from the window. 
  27. 70, And when I'm finished, I can click the 
  28. 72, Exit command. Now let's take a look at how 
  29. 75, this program accomplishes its work. The 
  30. 78, mnuItemOpen_Click event procedure is the 
  31. 81, heart of this program. The first thing 
  32. 84, it does is build a wrap character that I 
  33. 87, can use to add lines to my open text 
  34. 91, box. And it uses the Filter property to 
  35. 94, create the filter that is in the Open 
  36. 96, dialog box and the ShowOpen method to open 
  37. 100, the dialog box with the CommonDialog1 
  38. 102, object. If the filename that was specified 
  39. 107, by the user is not an empty file, then I 
  40. 111, want to go ahead and open the file and 
  41. 113, display it in the dialog box. The first 
  42. 115, thing I do is set the MousePointer 
  43. 117, property of the form to 11, which is an hour 
  44. 119, glass shape because it could take a 
  45. 122, little bit of time to display this if it's 
  46. 123, quite a large file. And I want to use the 
  47. 126, Open command to open up the file and I 
  48. 130, want to set an error handler called Too 
  49. 132, Big in case my file is too big to be 
  50. 135, displayed in the window. If that's the 
  51. 137, case, I'll have an error, and I'll jump down 
  52. 139, to the label Too Big at the bottom of 
  53. 140, the program and I'll use a message box to 
  54. 143, say that the file is too large. And 
  55. 146, I'll jump to a clean-up routine, which is 
  56. 148, slightly above. And that clean-up routine 
  57. 151, simply sets the mouse pointer to zero, 
  58. 153, which resets its regular shape, closes 
  59. 155, the file, and exits the sub-program. Now, 
  60. 161, we hope this won't happen. Actually what
  61. 163, we hope happens is that I get a chance 
  62. 166, to read my file in a loop. And the way 
  63. 169, we do that is to read one line at a time 
  64. 172, with the Line Input statement. Put that 
  65. 175, into the AllText variable, and then 
  66. 178, when we're all finished reading that in, 
  67. 180, we'll go ahead and display that by 
  68. 183, assigning AllText to the Text property of my 
  69. 187, text box object. I'll set the caption of 
  70. 192, the label in my program to the name of 
  71. 194, the file. And I'll go ahead and enable my 
  72. 198, Close item and enable my Open command 
  73. 203, and my dialog box for scrolling. So that's 
  74. 209, a quick look at this event procedure. 
  75. 212, And we'll see that a little bit more in 
  76. 213, the next demonstration when I create a 
  77. 214, file editor. You might want to follow 
  78. 216, these steps whenever you want to use a text 
  79. 219, box in your program.
  80. 222, END